package com.zhifa.redirect.controller;

import com.zhifa.redirect.vo.BodyVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/nacos/test")
@Slf4j
public class NacosRedirectController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/list")
    public Object list(HttpServletRequest request, HttpServletResponse response){

        Map<String, Object> result = new HashMap<>();
        result.put("a", 1);
        result.put("b", 2);
        result.put("c", 3);
        result.put("nacos", "nacos");
        //String body = restTemplate.getForEntity("http://localhost:8081/nacos/test/list", String.class).getBody();
        //result.put("nacos_to_eureka", body);
        return result;
    }
    @GetMapping("/list1")
    public Object list1(HttpServletRequest request, HttpServletResponse response){

        Map<String, Object> result = new HashMap<>();
        result.put("a", 1);
        result.put("b", 2);
        result.put("c", 3);
        result.put("d", 4);
        return result;
    }

    @PostMapping("/save")
    public Object save(HttpServletRequest request, HttpServletResponse response) {

        return request.getParameterMap();
    }

    @PostMapping("/body")
    public Object body(HttpServletRequest request, HttpServletResponse response, @RequestBody BodyVo bodyVo) {
        log.info("BodyVo:{}",bodyVo);
        return bodyVo;
    }




}
